package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjtordermember;
import com.chezhujie.www.persistence.CzjtordermemberMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 会员订单
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjtordermemberService extends BaseService<Czjtordermember> {
    @Autowired
    private CzjtordermemberMapper czjtordermemberMapper;

    @Autowired
    public void setBaseMapper(CzjtordermemberMapper czjtordermemberMapper) {
        this.baseMapper = czjtordermemberMapper;
    }

    public List<Map<String,Object>> getListUserinfoId(Map<String, Object> param) {
        return czjtordermemberMapper.listUserinfoId(param);
    }

    public void checkEntity(Czjtordermember czjtordermember) throws ClassCheckException {
        if(czjtordermember.getTordermemberId()!=null&&czjtordermember.getTordermemberId().length()>19){
            throw new ClassCheckException("会员订单主键不能超过19个字符");
        }
        if(czjtordermember.getOrderCode()!=null&&czjtordermember.getOrderCode().length()>25){
            throw new ClassCheckException("会员订单订单编号不能超过25个字符");
        }
        if(czjtordermember.getBusinessId()!=null&&czjtordermember.getBusinessId().length()>19){
            throw new ClassCheckException("会员订单商家不能超过19个字符");
        }
        if(czjtordermember.getRemark()!=null&&czjtordermember.getRemark().length()>100){
            throw new ClassCheckException("会员订单备注不能超过100个字符");
        }
    }
    public void checkListEntity(List<Czjtordermember> listCzjtordermember) throws ClassCheckException {

        for (Czjtordermember czjtordermember : listCzjtordermember) {
            checkEntity(czjtordermember);
        }

    }

    public Map<String,Object> getOrderedByNo(String orderNo) {
        return czjtordermemberMapper.getOrderedByNo(orderNo);
    }
    public void updateOrderStatus(String orderno,Integer orderStatus){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderno", orderno);
        map.put("orderStatus", orderStatus);
        czjtordermemberMapper.updateOrderStatus(map);
    }
}
